package com.yaofeng.mybatis.modules.sys.controller;



import org.springframework.beans.factory.annotation.Autowired;
import com.yaofeng.mybatis.modules.sys.service.IRoleMenuService;
import com.yaofeng.mybatis.modules.sys.entity.RoleMenu;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yaofeng.mybatis.annotation.Log;
import com.yaofeng.mybatis.common.PageInfo;
import com.yaofeng.mybatis.common.ResponseInfo;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 角色和菜单关联表 前端控制器
 * </p>
 *
 * @author yaofeng
 * @since 2019-11-13
 */
@RestController
@RequestMapping("/sys/role-menu")
public class RoleMenuController {

    @Autowired
    private IRoleMenuService roleMenuService;

    @GetMapping("/list")
    @RequiresAuthentication
    @Log(value = "列表")
    public ResponseInfo list(@RequestParam Map<String, Object> params, @RequestParam(defaultValue = "1") Long pageNum, @RequestParam(defaultValue = "50") Long pageSize) {
        IPage page = roleMenuService.page(new Page<>(pageNum, pageSize), Wrappers.<RoleMenu>lambdaQuery());
        return ResponseInfo.success(new PageInfo(page));
    }

     /**
     * 保存
     * @param roleMenu
     * @return
     */
    @PostMapping("/save")
    @RequiresAuthentication
    @Log(value = "保存")
    public  ResponseInfo save(@RequestBody RoleMenu roleMenu){
        roleMenuService.save(roleMenu);
        return ResponseInfo.success();
    }


    /**
     * 更新
     * @param roleMenu
     * @return
     */
    @PutMapping("/update")
    @RequiresAuthentication
    @Log(value = "更新")
    public  ResponseInfo update(@RequestBody  RoleMenu roleMenu){
        roleMenuService.updateById(roleMenu);
        return ResponseInfo.success();
    }


    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping ("/delete")
    @RequiresAuthentication
    @Log(value = "删除")
    public  ResponseInfo delete(Long id){
       roleMenuService.removeById(id);
        return ResponseInfo.success();
    }




}
